<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <style type="text/css">
        html,
        body {
            background-color: white;
        }

        header {
            border-bottom: 1px solid #ccc;
            padding: 25px 0;
        }

        span {
            padding: 10px 5px;
            margin: 5px;
            display: inline-block;
            background-color: #e8e8e8;
        }

        .hover {
            opacity: .4;
        }

        .btn {
            position: relative;
            left: 10px;
            top: 20px;
            width: 180px;
        }
    </style>
</head>

<body id="bd">
    <div class="main">
        <header>
            <h1>qiniuStorage</h1>
            <mark>
                使用前请详细阅读模块文档
            </mark>
        </header>
        <div class="btn">
            <span tapmode="hover" onclick="fnconfigUploader()">configUploader</span>
            <span tapmode="hover" onclick="fnstart()">start</span>
            <span tapmode="hover" onclick="fncancel()">cancel</span>
            <span tapmode="hover" onclick="fnaddEventListener()">addEventListener</span>
        </div>
    </div>
</body>
<script type="text/javascript">
    var qiniuStorage;
    apiready = function() {
        qiniuStorage = api.require('qiniuStorage');
    };

    function fnconfigUploader() {
        qiniuStorage.configUploader({
            params: {
                "x:foo": "fooval"
            },
            checkCrc: false,
            mimeType: '',
            zone: 'z0'
        });
    }

    function fnstart() {
        // 从服务端获取token
        //var token = $token;

        api.getPicture({
            sourceType: 'library',
            encodingType: 'jpg',
            mediaValue: 'pic',
            destinationType: 'url',
            allowEdit: true,
            quality: 50,
            targetWidth: 100,
            targetHeight: 100,
            saveToPhotoAlbum: false
        }, function(ret, err) {
            if (ret) {
                //alert(JSON.stringify(ret));

                qiniuStorage.start({
                    token: token,
                    path: ret.data,
                    key: 'fghyjy'
                });
            } else {
                alert(JSON.stringify(err));
            }
        });
    }

    function fncancel() {
        qiniuStorage.cancel();
    }

    function fnaddEventListener() {
        qiniuStorage.addEventListener(function(ret) {
            console.log(JSON.stringify(ret));
        });
    }
</script>

</html>
